package com.andyyan.elasticsearch.client.def.model;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by yantingxin on 16-6-29.
 */
public class Item<T> implements Serializable {

    private static final long serialVersionUID = -6979689790740365296L;
    private T object;

    //因为可能需要两个或多个字段高亮 ，key为field，value为该高亮的内容和位置
    private Map<String, HighlightItem> highlightItemMap;

    public T getObject() {
        return object;
    }

    public void setObject(T object) {
        this.object = object;
    }

    public Map<String, HighlightItem> getHighlightItemMap() {
        return highlightItemMap;
    }

    public void setHighlightItemMap(Map<String, HighlightItem> highlightItemMap) {
        this.highlightItemMap = highlightItemMap;
    }

    public HighlightItem getHighlighItem(String field) {
        if (highlightItemMap != null) {
            return highlightItemMap.get(field);
        }
        return null;
    }

    public void putHighlightItem(String field, HighlightItem highlightItem) {
        if (highlightItemMap == null) {
            highlightItemMap = new ConcurrentHashMap<String, HighlightItem>();
        }
        highlightItemMap.put(field, highlightItem);
    }

    @Override
    public String toString() {
        return "Item{" +
                "object=" + object +
                ", highlightItemMap=" + highlightItemMap +
                '}';
    }
}
